﻿//-----------------------------------------------------------------------
// <copyright file="RuleSetParser.cs" company="tuliprules.org">
//     Copyright (c) 2010 tuplelister, tuliprules.org.
// </copyright>
// <summary>This is the RuleSetParser class.</summary>
//-----------------------------------------------------------------------

namespace Tulip.Rules
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;

    /// <summary>
    /// The default rule set parser.  Used to parse Tulip rules.
    /// </summary>
    public class RuleSetParser : IRuleSetParser
    {
        /// <summary>
        /// Read-only collection of rules.
        /// </summary>
        private readonly ReadOnlyCollection<Rule> rules = new ReadOnlyCollection<Rule>(new List<Rule>());

        /// <summary>
        /// Gets a URI that can be used as a type specifer for the rule set.
        /// </summary>
        /// <value>
        /// The build component of the version number.
        /// </value>
        public Uri RuleSetType
        {
            get
            {
                return new Uri(Properties.Resources.TulipRuleSetUri, UriKind.Absolute);
            }
        }

        /// <summary>
        /// Gets the content of the rule or rule set.
        /// </summary>
        /// <value>
        /// The content of the rule or rule set.
        /// </value>
        public string Presentation { get; private set; }

        /// <summary>
        /// Gets the model representing the rule or rule set.
        /// </summary>
        /// <value>
        /// The model representing the rule or rule set.
        /// </value>
        public object Model { get; private set; }

        /// <summary>
        /// Gets a read-only collection of rules.
        /// </summary>
        /// <value>
        /// A read-only collection of rules.
        /// </value>
        public ReadOnlyCollection<Rule> Rules
        {
            get
            {
                return this.rules;
            }
        }

        /// <summary>
        /// Parses rule content.
        /// </summary>
        /// <param name="content">
        /// The content of the rule or rule set.
        /// </param>
        /// <returns>
        /// True, if parsing completed; false if the parse terminated abnormally.
        /// </returns>
        public bool Parse(string content)
        {
            // TODO: Implement Tulip rule parser functionality
            this.Presentation = content;
            this.Model = content;

            return true;
        }

        /// <summary>
        /// Parses a rule model.
        /// </summary>
        /// <param name="model">
        /// The model representing the rule or rule set.
        /// </param>
        /// <returns>
        /// True, if parsing completed; false if the parse terminated abnormally.
        /// </returns>
        public bool Parse(object model)
        {
            // TODO: Implement Tulip rule parser functionality
            this.Presentation = model.ToString();
            this.Model = model;

            return true;
        }
    }
}
